package com.axjy.scheduler.service.impl;

import com.axjy.comm.pojo.TpScheduler;
import com.axjy.comm.pojo.TpSchedulerSeatPrice;
import com.axjy.scheduler.mapper.SchedulerMapper;
import com.axjy.scheduler.mapper.SchedulerSeatPriceMapper;
import com.axjy.scheduler.service.SchedulerService;
import com.axjy.scheduler.vo.SeatPriceVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
import java.util.stream.Collectors;

@Service("schedulerService")
public class SchedulerServiceImpl implements SchedulerService {

    @Resource
    private SchedulerMapper schedulerMapper;

    @Resource
    private SchedulerSeatPriceMapper schedulerSeatPriceMapper;


    @Override
    public List<TpScheduler> queryItemScheduler(Integer itemId) {
        QueryWrapper<TpScheduler> queryWrapper= Wrappers.query();
        queryWrapper.eq("item_id",itemId);
        return schedulerMapper.selectList(queryWrapper);
    }

    @Override
    public List<SeatPriceVo> queryItemPrice(Integer scheduleId) {
       QueryWrapper<TpSchedulerSeatPrice> queryWrapper=Wrappers.query();
       queryWrapper.eq("schedule_id",scheduleId);
       List<TpSchedulerSeatPrice> list= schedulerSeatPriceMapper.selectList(queryWrapper);
       List<SeatPriceVo> list2= list.stream().map(tpSchedulerSeatPrice -> {
           SeatPriceVo seatPriceVo=new SeatPriceVo();
           seatPriceVo.setId(tpSchedulerSeatPrice.getId());
           seatPriceVo.setPrice(tpSchedulerSeatPrice.getPrice());
           seatPriceVo.setScheduleId(tpSchedulerSeatPrice.getScheduleId());
           seatPriceVo.setIsHaveSeat(tpSchedulerSeatPrice.getSeatNum()>0?1:0);
            return  seatPriceVo;
        }).collect(Collectors.toList());
        return list2;
    }
}
